﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Reactive;
using System.Reactive.Linq;
using System.Collections.Generic;
using System.Diagnostics;


namespace HaoLab.Library
{
    public class Renew
    {
        List<KeyValuePair<string, string>> Params;

        Uri uri;

        const string host = "http://202.204.72.4:8080/reader/";
        HttpWebClient wc;

        public Renew()
        {
            uri = new Uri(host + "ajax_renew.php");
            wc = new HttpWebClient();

            DateTime t = new DateTime(1969, 12, 25);
            long iii = (DateTime.Now.ToUniversalTime().Ticks - t.Ticks) / 1000;

            Params = new List<KeyValuePair<string, string>>();
            Params.Add(new KeyValuePair<string, string>("bar_code", "00921206"));
            Params.Add(new KeyValuePair<string, string>("time", iii.ToString()));

            Login log = new Login();
            log.Test().Subscribe(cc => wc.Cookies = cc);
            
        }

        public void Do()
        {
            DateTime t = new DateTime(1970, 1,1);
            long iii = (DateTime.Now.ToUniversalTime().Ticks - t.Ticks) / 1000;

            wc.UploadStringCompleted += new UploadStringCompletedEventHandler((s, e) =>
            {
                Debug.WriteLine(e.Result);
            });

            Params = new List<KeyValuePair<string, string>>();
            Params.Add(new KeyValuePair<string, string>("bar_code", "00921206"));
            Params.Add(new KeyValuePair<string, string>("time", iii.ToString()));


            wc.PostHtmlForm(new Uri(host + "ajax_renew.php"), Params);
        }
    }
}
